using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class TankBase : MonoBehaviour
{
    public int atk;
    public int def;
    public int maxHp = 100;
    public int hp;

    public float moveSpeed = 10;
    public float roundSpeed = 100;
    public float HeadRoundSpeed = 100;

    public GameObject deadEff;

    //炮台
    public Transform turretObject;
    public abstract void Fire();

    /// <summary>
    /// 受伤
    /// </summary>
    /// <param name="other"></param>
    public virtual void Hurt(TankBase other)
    {
        int temp = other.atk - def;
        if (temp < 0) return;
        this.hp -= temp;
        if (this.hp <= 0)
        {
            this.hp = 0;
            //死亡
            DestroyTank();
        }
    }

    public virtual void DestroyTank()
    {
        Destroy(this.gameObject);
        if (deadEff != null)
        {
            GameObject instantiate = Instantiate(deadEff, this.transform.position, this.transform.rotation);
            //改变音效
            AudioSource audioSource = instantiate.GetComponent<AudioSource>();
            audioSource.volume = GameDataManager.Instance.musicData.soundValue;
            audioSource.mute = !GameDataManager.Instance.musicData.isOpenMusic;
        }
    }
}